package com.bdqn.t296.noso.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bdqn.t296.noso.entity.*;
import com.bdqn.t296.noso.service.UserRegisertService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.sql.Date;
import java.util.Calendar;
import java.util.List;

/**
 * 用户挂号
 */
@Controller
@RequestMapping("/register")
public class UserRegisterController {
    @Autowired
    UserRegisertService userRegisertService;

    @RequestMapping("/registerList")
    public String registerList() {
        return "redirect:/register/registerPage";
    }

    //模糊分页查询
    @RequestMapping("/registerPage")
    public Object mobu(ReportVo reportVo, Model model, String params, Integer cc, HttpSession session, @RequestParam(required = false, defaultValue = "1") int current) {
        reportVo.setCc(cc);
        //将数据存储到session中
        session.setAttribute("ban", cc);
        //creportService.upddang();
        String reportName = params;
        reportVo.setReportName(reportName);
        Page<ReportVo> page = new Page<ReportVo>(current, 5);
        IPage<ReportVo> mobu = userRegisertService.sel(page, reportVo);
        System.out.println("总记录数 ---- --> " + mobu.getTotal());
        System.out.println("总页数 ------ --> " + mobu.getPages());
        System.out.println("当前页数 ----- -> " + mobu.getCurrent());
        System.out.println("每页记录数 -----> " + mobu.getSize());
        System.out.println("当前记录： -----> ");
        model.addAttribute("report", mobu);
        return "hospital/register";
    }

    //查询所有的科室
    @RequestMapping("/seldep")
    @ResponseBody
    public Object seldep() {
        List<CDepartments> seldep = userRegisertService.seldep();
        return seldep;
    }

    //查询所有的挂号类型
    @RequestMapping("/selreg")
    @ResponseBody
    public Object selreg() {
        List<CRegisteredtype> selreg = userRegisertService.selreg();
        return selreg;
    }

    //查询医生信息
    @RequestMapping("/seldoctor")
    @ResponseBody
    public Object seldoctor(CDoctor cDoctor) {
        Calendar calendar = Calendar.getInstance();
        Integer data = calendar.get(Calendar.DAY_OF_WEEK) - 1;//获取当前是星期几
        if (data == 1) {
            List<CDoctor> one = userRegisertService.one(cDoctor);
            return one;
        } else if (data == 2) {
            List<CDoctor> two = userRegisertService.two(cDoctor);
            return two;
        } else if (data == 3) {
            List<CDoctor> three = userRegisertService.three(cDoctor);
            return three;
        } else if (data == 4) {
            List<CDoctor> four = userRegisertService.four(cDoctor);
            return four;
        } else if (data == 5) {
            System.out.println(data);
            List<CDoctor> five = userRegisertService.five(cDoctor);
            return five;
        } else if (data == 6) {
            List<CDoctor> six = userRegisertService.six(cDoctor);
            return six;
        } else {
            List<CDoctor> seven = userRegisertService.seven(cDoctor);
            return seven;
        }
    }

    //根据挂号类型查找该类型的价格
    @RequestMapping("/seltymo")
    @ResponseBody
    public Object seltymo(CRegisteredtype cRegisteredtype) {
        Integer seltymo = userRegisertService.seltymo(cRegisteredtype);
        return seltymo;
    }

    //添加新的挂号
    @RequestMapping("/addreport")
    public Object addre(CReport cReport) {
        Date date = new Date(System.currentTimeMillis());
        cReport.setTime(date);
        int addre = userRegisertService.addre(cReport);
        if (addre == 1) {
            return "redirect:/register/registerPage";
        } else {
            return "添加失败，请联系管理员";
        }
    }

}
